home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '87 / Source ƒ.sea / Source ƒ / emacs source ƒ / HP150.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  9.2 KB  |  444 lines  |  [TEXT/MARC]

  1. /*
  2.  * The routines in this file provide support for HP150 screens
  3.  * and routines to access the Keyboard through KEYCODE mode.
  4.  * It compiles into nothing if not an HP150 screen device.
  5.  * added by Daniel Lawrence
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include        "estruct.h"
  12. #include    "edef.h"
  13.  
  14. #if     HP150
  15.  
  16. #define NROW    24                      /* Screen size.                 */
  17. #define NCOL    80                      /* Edit if you want to.         */
  18. #define    MARGIN    8            /* size of minimim margin and    */
  19. #define    SCRSIZ    64            /* scroll size for extended lines */
  20. #define    NPAUSE    15            /* # times thru update to pause */
  21. #define BEL     0x07                    /* BEL character.               */
  22. #define ESC     0x1B                    /* ESC character.               */
  23.  
  24. extern  int     openhp();               /* Forward references.          */
  25. extern  int     ttgetc();
  26. extern  int     ttputc();
  27. extern  int     ttflush();
  28. extern    int    hpflush();
  29. extern  int     closehp();
  30. extern    int    hp15kopen();
  31. extern    int    hp15kclose();
  32. extern  int     hp15move();
  33. extern  int     hp15eeol();
  34. extern  int     hp15eeop();
  35. extern  int     hp15beep();
  36. extern    int    gethpkey();
  37. extern    int    hp15rev();
  38. #if    COLOR
  39. extern    int    hp15fcol();
  40. extern    int    hp15bcol();
  41. #endif
  42.  
  43. /* weird to ascii translation table */
  44.  
  45. char trans[][2] = {
  46.     0x24,    9,    /* tab */
  47.     0x25,    13,    /* ret */
  48.     0x27,    8,    /* backspace */
  49.     0x30,    48,    /* zero */
  50.     0x31,    49,    /* one */
  51.     0x32,    50,    /* two */
  52.     0x33,    51,    /* three */
  53.     0x34,    52,    /* four */
  54.     0x35,    53,    /* five */
  55.     0x36,    54,    /* six */
  56.     0x37,    55,    /* seven */
  57.     0x38,    56,    /* eight */
  58.     0x39,    57,    /* nine */
  59.     0x50,    13,    /* enter */
  60.     0x54,    27,    /* break -> ESC */
  61.     0x55,    27,    /* esc */
  62.     0x58,    24,    /* stop -> ^X */
  63.     0x70,    45,    /* N-minus */
  64.     0x71,    42,    /* N-asterisk */
  65.     0x72,    43,    /* N-plus */
  66.     0x73,    47,    /* N-slash */
  67.     0x74,    44,    /* N-comma */
  68.     0x75,    13,    /* N-enter */
  69.     0x76,    9,    /* N-tab */
  70.     0x77,    46    /* N-period */
  71. };
  72.  
  73. #define NTRANS    sizeof(trans) / 2
  74.  
  75. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  76. int capslock = 0;    /* caps lock flag */
  77.  
  78. /*
  79.  * Standard terminal interface dispatch table. Most of the fields point into
  80.  * "termio" code.
  81.  */
  82. TERM    term    = {
  83.         NROW-1,
  84.         NCOL,
  85.     MARGIN,
  86.     SCRSIZ,
  87.     NPAUSE,
  88.     openhp,
  89.         closehp,
  90.     hp15kopen,
  91.     hp15kclose,
  92.     gethpkey,
  93.         ttputc,
  94.         hpflush,
  95.         hp15move,
  96.         hp15eeol,
  97.         hp15eeop,
  98.         hp15beep,
  99.         hp15rev
  100. #if    COLOR
  101.     , hp15fcol,
  102.     hp15bcol
  103. #endif
  104. };
  105.  
  106. hp15move(row, col)
  107. {
  108.         ttputc(ESC);
  109.         ttputc('&');
  110.         ttputc('a');
  111.         hp15parm(col);
  112.         ttputc('c');
  113.         hp15parm(row);
  114.         ttputc('R');
  115. }
  116.  
  117. hpflush()
  118.  
  119. {
  120.  
  121. }
  122.  
  123. hp15eeol()
  124. {
  125.         ttputc(ESC);
  126.         ttputc('K');
  127. }
  128.  
  129. hp15eeop()
  130. {
  131.         ttputc(ESC);
  132.         ttputc('J');
  133. }
  134.  
  135. hp15rev(status)        /* change the reverse video status */
  136.  
  137. int status;    /* TRUE = on, FALSE = off */
  138.  
  139. {
  140.     ttputc(ESC);
  141.     ttputc('&');
  142.     ttputc('d');
  143.     ttputc((status != FALSE) ? 'B': '@');
  144. }
  145.  
  146. hp15beep()
  147. {
  148.         ttputc(BEL);
  149.         ttflush();
  150. }
  151.  
  152. hp15parm(n)
  153. register int    n;
  154. {
  155.         register int    q;
  156.  
  157.         q = n/10;
  158.         if (q != 0)
  159.                 hp15parm(q);
  160.         ttputc((n%10) + '0');
  161. }
  162.  
  163. #if    COLOR
  164. hp15fcol()    /* we really can't do colors here, so just ignore it */
  165. {
  166. }
  167.  
  168. hp15bcol()    /* we really can't do colors here, so just ignore it */
  169. {
  170. }
  171. #endif
  172.  
  173. gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  174.  
  175. {
  176.     static int keepflag = 0;    /* kept ahead char flag */
  177.     static int keepchar = 0;    /* kept ehead flag */
  178.     int c;
  179.     int devid;            /* device ID */
  180.     int ctype;            /* type of character gotten */
  181.     int shiftb;            /* state of shift keys */
  182.     int i;
  183.     
  184.     /* if we are in an extended char sequence, finish it */
  185.     if (keepflag != 0) {
  186.         keepflag = 0;
  187.         return(keepchar);
  188.     }
  189.  
  190.     /* grab the next 4 char sequence */
  191. next:    shiftb = ttgetc();
  192.     devid = ttgetc();
  193.     c = ttgetc();
  194.     ttgetc();        /* skip null byte */
  195.     
  196.     /* make sure we are from the keyboard */
  197.     if (devid != 192)
  198.         goto next;
  199.  
  200.     /* if normal ascii, return it */
  201.     if ((shiftb & 0x80) == 0) {
  202.         if (capslock && c >= 'a' && c <= 'z')
  203.             c -= 32;
  204.         return(c);
  205.     }
  206.  
  207.     /* check specifically for the caps lock key */
  208.     if (c == 0x56) {
  209.         capslock = ~capslock;
  210.         goto next;
  211.     }
  212.  
  213.     /* check to see if it needs translation */
  214.     for (i=0; i < NTRANS; i++)
  215.         if (trans[i][0] == c)
  216.             return((int)trans[i][1]);
  217.  
  218.     /* other wise, shove it in the keep char and return the leadin code */
  219.     keepchar = c;
  220.     keepflag = 1;
  221.     return(0);
  222. }
  223.  
  224. openhp()        /* open the HP150 screen for input */
  225.  
  226. {
  227.     revexist = TRUE;
  228. }
  229.  
  230. closehp()        /* close the HP150 screen for input */
  231.  
  232. {
  233. }
  234.  
  235. hp15kopen()        /* open the HP150 keyboard for input */
  236.  
  237. {
  238.     /* define key charectoristics with AGIOS call (0, 40) */
  239.     defkey();
  240.  
  241.     /* Turn on RAW mode with MSDOS call 44h */
  242.     rawon();
  243.  
  244.     /* Turn off Control-C checking  MS-DOS 33h */
  245.     ckeyoff();
  246.  
  247.     /* Turn on keycode mode with AGIOS call (0,43) */
  248.     keycon();
  249.  
  250.     /* display the application softkey labels */
  251.     dsplbls();
  252. }
  253.  
  254. hp15kclose()        /* close the HP150 keyboard for input */
  255.  
  256. {
  257.     /* define key charectoristics with AGIOS call (0, 40) */
  258.     undefkey();
  259.     
  260.     /* Turn off RAW mode with MSDOS call 44h */
  261.     rawoff();
  262.  
  263.     /* Turn on Control-C checking  MS-DOS 33h */
  264.     ckeyon();
  265.  
  266.     /* Turn off keycode mode with AGIOS call (0,43) */
  267.     keycoff();
  268. }
  269.  
  270. rawon()        /* put the HP150 keyboard into RAW mode */
  271.  
  272. {
  273.     /* get the IO control info */
  274.  
  275.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  276.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  277.     intdos(&r, &r);        /* go fer it */
  278.  
  279.     r.h.dh = 0;        /* clear high byte for put */
  280.     r.h.dl |= 0x20;        /* set raw bit */
  281.  
  282.     /* and put it back */
  283.  
  284.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  285.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  286.     intdos(&r, &r);        /* go fer it */
  287. }
  288.  
  289. rawoff()    /* put the HP150 keyboard into COOKED mode */
  290.  
  291. {
  292.     /* get the IO control info */
  293.  
  294.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  295.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  296.     intdos(&r, &r);        /* go fer it */
  297.  
  298.     r.h.dh = 0;        /* clear high byte for put */
  299.     r.h.dl &= 0xdf;        /* set raw bit */
  300.  
  301.     /* and put it back */
  302.  
  303.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  304.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  305.     intdos(&r, &r);        /* go fer it */
  306. }
  307.  
  308.  
  309. ckeyoff()    /* turn control-C trapping off */
  310.  
  311. {
  312.     r.h.ah = 0x33;    /* ctrl-break check */
  313.     r.h.al = 1;    /* set the state of the ctrl-break check */
  314.     r.h.dl = 0;    /* turn it off */
  315.     intdos(&r, &r);
  316. }
  317.  
  318. ckeyon()    /* turn control-C trapping on */
  319.  
  320. {
  321.     r.h.ah = 0x33;    /* ctrl-break check */
  322.     r.h.al = 1;    /* set the state of the ctrl-break check */
  323.     r.h.dl = 1;    /* turn it on */
  324.     intdos(&r, &r);
  325. }
  326.  
  327. agios(buf, len)    /* perform an AGIOS call */
  328.  
  329. char *buf;    /* sequence of bytes in command */
  330. int len;    /* length of command in bytes */
  331.  
  332. {
  333.     r.x.ax = 0x4403;    /* I/O ctrl write */
  334.     r.x.bx = 1;        /* console handle */
  335.     r.x.cx = len;        /* buffer length */
  336.     r.x.dx = (unsigned)buf;    /* buffer address */
  337.     return(intdos(&r, &r));    /* do it */
  338. }
  339.  
  340. keycon()    /* turn keycode mode on */
  341.  
  342. {
  343.     static char cmd[] = {43, 0, 1};
  344.  
  345.     return(agios(&cmd[0], 3));
  346. }
  347.  
  348. keycoff()    /* turn keycode mode off */
  349.  
  350. {
  351.     static char cmd[] = {43, 0, 0};
  352.  
  353.     return(agios(&cmd[0], 3));
  354. }
  355.  
  356. defkey()    /* change all special keys to intercept mode */
  357.  
  358. {
  359.     static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  360.  
  361.     return(agios(&cmd[0], 6));
  362. }
  363.  
  364. undefkey()    /* change all special keys to intercept mode */
  365.  
  366. {
  367.     static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  368.  
  369.     return(agios(&cmd[0], 6));
  370. }
  371.  
  372. dsplbls()    /* display the application softkey labels on the screen */
  373.  
  374. {
  375.     static char cmd[] = {11, 0};
  376.  
  377.     return(agios(&cmd[0], 2));
  378. }
  379.  
  380. #if    FLABEL
  381. fnclabel(f, n)        /* label a function key */
  382.  
  383. int f,n;    /* default flag, numeric argument */
  384.  
  385. {
  386.     register int status;    /* return status */
  387.     register int i;        /* loop index */
  388.     char lbl[17];    /* returned label contents */
  389.     /* AGIOS command buffer */
  390.     static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
  391.     /*                   code  key#  ptr to      top    bottom
  392.                                      label string  attribute */
  393.     union {        /* union to cast ptr into AGIOS arg string */
  394.         char *ptr;    /* pointer to arg string */
  395.         char cstr[4];
  396.     } ptru;
  397.  
  398.     /* must have a numeric argument */
  399.     if (f == FALSE) {
  400.         mlwrite("%Need function key number");
  401.         return(FALSE);
  402.     }
  403.  
  404.     /* and it must be a legal key number */
  405.     if (n < 1 || n > 8) {
  406.         mlwrite("%Function key number out of range");
  407.         return(FALSE);
  408.     }
  409.  
  410.     /* get the string to send */
  411.     status = mlreply("Label contents: ", &lbl[0], 17);
  412.     if (status != TRUE)
  413.         return(status);
  414.  
  415.     /* pad the label out */
  416.     for (i=0; i < 17; i++) {
  417.         if (lbl[i] == 0)
  418.             break;
  419.     }
  420.     for (; i < 16; i++)
  421.         lbl[i] = ' ';
  422.     lbl[16] = 0;
  423.  
  424.     /* set up the parameters */
  425.     cmd[2] = n;            /* function key number */
  426.     ptru.ptr = &lbl[0];        /* set up pointer to label string */
  427. force:    cmd[4] = ptru.cstr[0];
  428.     cmd[5] = ptru.cstr[1];
  429.     cmd[6] = ptru.cstr[2];
  430.     cmd[7] = ptru.cstr[3];
  431.  
  432.     /* and send it out */
  433.     agios(&cmd[0], 12);
  434.     return(TRUE);
  435. }
  436. #endif
  437. #else
  438.  
  439. h15hello()
  440.  
  441. {
  442. }
  443. #endif
  444.